package cn.ysnk.generateCode;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.plaf.FontUIResource;

import com.jfinal.kit.PathKit;

public class AuthPrint {
	/**
	 * 打印汉子在控制台，建议两个汉字即可~~~~
	 * @param s
	 * @throws IOException
	 * @throws FontFormatException
	 * author：夏尉
	 */
	public static void print(String s) throws IOException, FontFormatException{
		int width = 40;     
	    int height = 18;     
	    Font font = new Font("黑体", Font.BOLD, 20);//Font.createFont(Font.TRUETYPE_FONT, new File(PathKit.getRootClassPath()+"/FZLTCXHJW.ttf")).deriveFont(20).deriveFont(20f);//
	    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);     
	    Graphics2D g2 = (Graphics2D)bi.getGraphics();     
	    g2.setBackground(Color.WHITE); 
	    g2.clearRect(0, 0, width, height);     
	    g2.setPaint(Color.black);     
	    g2.setFont(font);
	    FontRenderContext context = g2.getFontRenderContext();     
	    Rectangle2D bounds = font.getStringBounds(s, context);  
	    double x = (width - bounds.getWidth()) / 2;     
	    double y = (height - bounds.getHeight()) / 2;     
	    double ascent = -bounds.getY();     
	    double baseY = y + ascent;     
	    g2.drawString(s, (int)x, (int)baseY);
	    System.out.print("|");
	    for(int index=0;index<width;index++){
	    	System.out.print("=");
	    }
	    System.out.println("|");
	    for(int j=0;j<height;j++){
	    	System.out.print("|");
	    	for(int i=0;i<width;i++){
	    		if(bi.getRGB(i, j)==-16777216){
	    			System.out.print("#");
	    		}else{
	    			System.out.print(" ");
	    		}
	    	}
	    	System.out.println("|");
	    }
	    System.out.print("|");
	    for(int index=0;index<width;index++){
	    	System.out.print("=");
	    }
	    System.out.println("|");
	}
	
	public static void main(String[] args) throws IOException, FontFormatException {
		print("兰艳");
	}
}
